<?
/**
 * Copyright 2007 Melange.
 *
 * This file is part of PHP-MVC.
 *
 * PHP-MVC is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * PHP-MVC is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with PHP-MVC; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @category    Melange
 * @package     php-mvc
 * @subpackage  action
 * @copyright   Copyright (c) 2007 Jeroen Simons. All rights reserved
 * @author      Bas Simons <basthebuilder@gmail.com>
 * @link        http://www.melange.nl/
 *
 */

 require_once("mvc/Action.php");

 class MappingDispatchAction extends Action {

        public function __construct() {
            $this->log =& LoggerManager::getLogger("MappingDispatchAction");
        }

        public function execute(ActionMapping &$mapping, LanguageForm &$form, Request &$request, Response &$response) {
              //treat parameter as methodname to call instead of execute
              $method = $this->getMethodName($mapping,$form,$request,$response);
              if(method_exists($this, $method)) {
                    return call_user_func(array($this, $method),$mapping,$form,$request,$response);
              } else {
                  return unspecified($mapping,$form,$request,$response);
              }

        }

        protected function unspecified(ActionMapping &$mapping, LanguageForm &$form, Request &$request, Response &$response){
             //todo
        }

        protected function getMethodName(ActionMapping &$mapping, LanguageForm &$form, Request &$request, Response &$response){
             return $mapping->getParameter();
        }


}